{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>20130701</td>\n",
       "      <td>32488348</td>\n",
       "      <td>5525022</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20130702</td>\n",
       "      <td>29037390</td>\n",
       "      <td>2554548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>20130703</td>\n",
       "      <td>27270770</td>\n",
       "      <td>5953867</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>20130704</td>\n",
       "      <td>18321185</td>\n",
       "      <td>6410729</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20130705</td>\n",
       "      <td>11648749</td>\n",
       "      <td>2763587</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>422</th>\n",
       "      <td>20140827</td>\n",
       "      <td>302194801</td>\n",
       "      <td>468164147</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>423</th>\n",
       "      <td>20140828</td>\n",
       "      <td>245082751</td>\n",
       "      <td>297893861</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>424</th>\n",
       "      <td>20140829</td>\n",
       "      <td>267554713</td>\n",
       "      <td>273756380</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>425</th>\n",
       "      <td>20140830</td>\n",
       "      <td>199708772</td>\n",
       "      <td>196374134</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>426</th>\n",
       "      <td>20140831</td>\n",
       "      <td>275090213</td>\n",
       "      <td>292943033</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>427 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         date  total_purchase_amt  total_redeem_amt\n",
       "0    20130701            32488348           5525022\n",
       "1    20130702            29037390           2554548\n",
       "2    20130703            27270770           5953867\n",
       "3    20130704            18321185           6410729\n",
       "4    20130705            11648749           2763587\n",
       "..        ...                 ...               ...\n",
       "422  20140827           302194801         468164147\n",
       "423  20140828           245082751         297893861\n",
       "424  20140829           267554713         273756380\n",
       "425  20140830           199708772         196374134\n",
       "426  20140831           275090213         292943033\n",
       "\n",
       "[427 rows x 3 columns]"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "data=pd.read_csv('task1_output.csv')\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>total_purchase_amt</th>\n",
       "      <th>total_redeem_amt</th>\n",
       "      <th>day_of_week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2013-07-01</td>\n",
       "      <td>32488348</td>\n",
       "      <td>5525022</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2013-07-02</td>\n",
       "      <td>29037390</td>\n",
       "      <td>2554548</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2013-07-03</td>\n",
       "      <td>27270770</td>\n",
       "      <td>5953867</td>\n",
       "      <td>Wednesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2013-07-04</td>\n",
       "      <td>18321185</td>\n",
       "      <td>6410729</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2013-07-05</td>\n",
       "      <td>11648749</td>\n",
       "      <td>2763587</td>\n",
       "      <td>Friday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>422</th>\n",
       "      <td>2014-08-27</td>\n",
       "      <td>302194801</td>\n",
       "      <td>468164147</td>\n",
       "      <td>Wednesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>423</th>\n",
       "      <td>2014-08-28</td>\n",
       "      <td>245082751</td>\n",
       "      <td>297893861</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>424</th>\n",
       "      <td>2014-08-29</td>\n",
       "      <td>267554713</td>\n",
       "      <td>273756380</td>\n",
       "      <td>Friday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>425</th>\n",
       "      <td>2014-08-30</td>\n",
       "      <td>199708772</td>\n",
       "      <td>196374134</td>\n",
       "      <td>Saturday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>426</th>\n",
       "      <td>2014-08-31</td>\n",
       "      <td>275090213</td>\n",
       "      <td>292943033</td>\n",
       "      <td>Sunday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>427 rows × 4 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "          date  total_purchase_amt  total_redeem_amt day_of_week\n",
       "0   2013-07-01            32488348           5525022      Monday\n",
       "1   2013-07-02            29037390           2554548     Tuesday\n",
       "2   2013-07-03            27270770           5953867   Wednesday\n",
       "3   2013-07-04            18321185           6410729    Thursday\n",
       "4   2013-07-05            11648749           2763587      Friday\n",
       "..         ...                 ...               ...         ...\n",
       "422 2014-08-27           302194801         468164147   Wednesday\n",
       "423 2014-08-28           245082751         297893861    Thursday\n",
       "424 2014-08-29           267554713         273756380      Friday\n",
       "425 2014-08-30           199708772         196374134    Saturday\n",
       "426 2014-08-31           275090213         292943033      Sunday\n",
       "\n",
       "[427 rows x 4 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "\n",
    "#根据时间，添加星期一列\n",
    "data['date'] = pd.to_datetime(data['date'], format='%Y%m%d')\n",
    "data['day_of_week'] = data['date'].dt.day_name()\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Friday 61 199407923.06557378 166467960.19672132 12163883307 10154545572\n",
      "Monday 61 260305810.0 217463865.4918033 15878654410 13265295795\n",
      "Saturday 61 148088068.29508197 112868942.08196722 9033372166 6885005467\n",
      "Sunday 61 155914551.93442622 132427205.06557377 9510787668 8078059509\n",
      "Thursday 61 236425594.03278688 176466674.8852459 14421961236 10764467168\n",
      "Tuesday 61 263582058.86885247 191769144.62295082 16078505591 11697917822\n",
      "Wednesday 61 254162607.83606556 194639446.5081967 15503919078 11873006237\n"
     ]
    }
   ],
   "source": [
    "grouped=data.groupby('day_of_week')\n",
    "for name,group in grouped:\n",
    "    count=len(group)\n",
    "    #求所有数据的平均值\n",
    "    total1=group['total_purchase_amt'].sum()\n",
    "    total2=group['total_redeem_amt'].sum()\n",
    "    mean1=total1/count\n",
    "    mean2=total2/count\n",
    "    print(name,count,mean1,mean2,total1,total2)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
